package com.gcstorage.tvdev.constants;

import android.net.Uri;
import android.os.Bundle;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.GsonUtils;
import com.gcstorage.tvdev.util.SpUtils;
import com.gcstorage.tvdev.util.UserHelper;


/**
 * 应用常量
 */
public class AppConstant {
    public static final String cityName = "cityName";
    public static final String cityHost = "cityHost";
    public static final String cityWebSocket = "cityWebSocket";
    public static final String map_box_url = "map_box_url";
    public static final String tenantId = "tenantId";
    public static final String clientId = "clientId";
    public static final String APP_ID_PREVIEW = "20";//在线预览
    public static final String APP_ID_EXCLUSIVE = "21";//专属消息


    /**
     * 获取门户登录用户信息， 提供给第三方使用
     */
    public static Bundle getUserBundle() {
        Bundle bundle = new Bundle();
        bundle.putString("host_address", AppConstant.getApiAddress());  //host地址
        bundle.putString("sp_key_id", UserHelper.instance().getUserId());  //用户ID
        bundle.putString("tenantId", SpUtils.getString(AppConstant.tenantId));
        bundle.putString("packageName", AppUtils.getAppPackageName());
        bundle.putString("userInfo", GsonUtils.toJson(UserHelper.instance().getUserInfo()));
        return bundle;
    }

    public static Bundle getUserBundle(String param) {
        Bundle bundle = getUserBundle();
        bundle.putString("param", param);
        return bundle;
    }

    /**
     * 获取门户定义的 启动第三方应用的 URL
     */
    public static String getGotoAppUrl(String appId) {
        return "gc://" + appId + "/gc/start";
    }

    /**
     * 获取 缓存的 服务器名称
     */
    public static String getServiceName() {
        return SpUtils.getString(AppConstant.cityName);
    }

    /**
     * 获取 缓存的IP（动态IP）
     *
     * @return 例如：http://112.124.46.129:20006/CJMYMH
     */
    public static String getApiAddress() {
        return SpUtils.getString(AppConstant.cityHost);
    }

    public static String getHostIp() {
        Uri uri = Uri.parse(getApiAddress());
        return uri.getHost();
    }

    public static int getHostPort() {
        Uri uri = Uri.parse(getApiAddress());
        return uri.getPort();
    }

    public static String getHostPath() {
        Uri uri = Uri.parse(getApiAddress());
        return uri.getPath();
    }

    public static String getWebSocketSuffix() {
        return SpUtils.getString(AppConstant.cityWebSocket);
    }

    public static String getBaseWebSocketUrl() {
        return getWebSocketSuffix();
    }

    //获取mapboxurl
    public static String getMapBoxUrl() {
        return SpUtils.getString(AppConstant.map_box_url);
    }

    //获取租户Id
    public static String getTenantId() {
        return SpUtils.getString(SpUtils.TAG_USER, Constant.SP_KEY_TENANT);
    }
}
